package com.yanfan.data.tdengine.service.impl;

import cn.hutool.core.lang.Snowflake;
import cn.hutool.core.util.IdUtil;
import com.yanfan.data.domain.SnmpResponse;
import com.yanfan.data.tdengine.config.SnmpTDengineConfig;
import com.yanfan.data.tdengine.dao.TDSnmpResponseDao;
import com.yanfan.data.tdengine.service.TDSnmpResponseService;
import org.springframework.context.ApplicationContext;

import java.util.List;

public class TDSnmpResponseServiceImpl implements TDSnmpResponseService {

    private final SnmpTDengineConfig tDengineConfig;
    private final TDSnmpResponseDao tdSnmpResponseDao;
    private final Snowflake snowflake;
    private final String dbName;
    private ApplicationContext applicationContext;

    public TDSnmpResponseServiceImpl(SnmpTDengineConfig _tDengineConfig, TDSnmpResponseDao _tdSnmpResponseDao) {
        this.tDengineConfig = _tDengineConfig;
        this.tdSnmpResponseDao = _tdSnmpResponseDao;
        snowflake = IdUtil.getSnowflake(1);
        this.dbName = _tDengineConfig.getDbName();
    }


    @Override
    public int insertSnmpResponse(SnmpResponse snmpResponse) {
        Long id = snowflake.nextId();
        snmpResponse.setId(String.valueOf(id));
        return tdSnmpResponseDao.save(dbName, snmpResponse);
    }

    @Override
    public List<SnmpResponse> TDSelect(SnmpResponse snmpResponse) {
        return tdSnmpResponseDao.TDSelect(dbName, snmpResponse);
    }

    @Override
    public SnmpResponse selectSnmpResponseById(Long id) {
        return tdSnmpResponseDao.selectSnmpResponseById(dbName, id);
    }
}
